package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.AssistRecord;
import com.qinggeng.project.system.service.IAssistRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 助力记录Controller
 * 
 * @author ruoyi
 * @date 2020-11-05
 */
@RestController
@RequestMapping("/system/record")
public class AssistRecordController extends BaseController
{
    @Autowired
    private IAssistRecordService assistRecordService;

    /**
     * 查询助力记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssistRecord assistRecord)
    {
        startPage();
        List<AssistRecord> list = assistRecordService.selectAssistRecordList(assistRecord);
        return getDataTable(list);
    }

    /**
     * 导出助力记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "助力记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AssistRecord assistRecord)
    {
        List<AssistRecord> list = assistRecordService.selectAssistRecordList(assistRecord);
        ExcelUtil<AssistRecord> util = new ExcelUtil<AssistRecord>(AssistRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 获取助力记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(assistRecordService.selectAssistRecordById(id));
    }

    /**
     * 新增助力记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "助力记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssistRecord assistRecord)
    {
        return toAjax(assistRecordService.insertAssistRecord(assistRecord));
    }

    /**
     * 修改助力记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "助力记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssistRecord assistRecord)
    {
        return toAjax(assistRecordService.updateAssistRecord(assistRecord));
    }

    /**
     * 删除助力记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "助力记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assistRecordService.deleteAssistRecordByIds(ids));
    }
}
